﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace TestCalc
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void calc_Click(object sender, EventArgs e)
        {
            
            ShowPage sp = new ShowPage();
            this.Visible = false;
            sp.ShowDialog(this);
            this.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void btn_Check_Click(object sender, EventArgs e)
        {
            lb_Show.Text = "";

            MySqlConnection conn = new MySqlConnection("server = localhost; user id = root;password = cally5075; database = test; persist security info = False");
            MySqlCommand comm = new MySqlCommand();
            MySqlDataReader reader = null;
            comm.Connection = conn;
            comm.CommandText = "select * from people where id = " + tb_ID.Text.ToString() +";";

            try
            {
                conn.Open();
                reader = comm.ExecuteReader();
                //while (reader.Read())
                if (reader.Read())
                {
                    //lb_Show.Text = "Data has been read.";
                    lb_Show.Text = "ID: " + reader.GetValue(0).ToString() + " Name: " + reader.GetValue(1).ToString() + " Add: " + reader.GetValue(2).ToString() + " and Birthday: " + reader.GetValue(3).ToString();
                    //lb_Show.Text = reader.GetValue(1).ToString();
                    //lb_Show.Text = reader.GetString(2);
                    //lb_Show.Text = reader.GetString(0) + " " + reader.GetString(3);


                }
                else
                {
                    lb_Show.Text = "无记录";
                }
            }
            catch (System.Exception ex)
            {
                lb_Show.Text = "Exception:" + ex.Message;
            }
            finally
            {
                reader.Close();
                conn.Close();
            }
            
        }

        private void lb_Show_Click(object sender, EventArgs e)
        {

        }

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFile openfile = new OpenFile();
            openfile.ShowDialog(this);
        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFile openfile = new OpenFile();
            openfile.ShowDialog(this);
        }

       

        private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }
        private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
        {

        }
        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog();
            sf.Filter = "txt文件|*.txt文件|所有文件|*.*";
            sf.AddExtension = true;
            sf.Title = "保存文件";
            if (sf.ShowDialog() == DialogResult.OK) 
            {

            }
        }

        private void btnTable_Click(object sender, EventArgs e)
        {
            ShowTable table = new ShowTable();
            table.ShowDialog(this);
            //this.Close();
        }

        private void btnMethod2_Click(object sender, EventArgs e)
        {
            GetExcel2 getexcel = new GetExcel2();
            getexcel.ShowDialog(this);
        }

        private void btnMethod3_Click(object sender, EventArgs e)
        {
            GetDataFromMySQL getdata = new GetDataFromMySQL();
            getdata.ShowDialog();
        }
    }
}
